<template>
    <div>
        <h2>病房添加</h2>
         <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">病房号(病房名称)</td>
                    <td>
                        <input type="text" v-model="info.HouseNum"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">所属科室</td>
                    <td>
                                <select v-model="info.KeId">
                                    <option value="">请选择</option>
                                    <option :value="item.Id" v-for="item in list">{{ item.KeName }}</option>
                                </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">床位总数量</td>
                    <td>
                        <input type="text" v-model="info.Num"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">床位状态</td>
                    <td>
                        <input type="radio" :value="1" name="state" v-model="info.State">已满</input>
                        <input type="radio" :value="0" name="state" v-model="info.State">未满</input>
                    </td>
                </tr>
                <tr>
                    <td align="right">空床数量</td>
                    <td>
                        <input type="text" v-model="info.LastNum"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">病房状态</td>
                    <td>
                        <input type="radio" :value="1" name="stateye" v-model="info.StateYe">启用</input>
                        <input type="radio" :value="0" name="stateye" v-model="info.StateYe">维修</input>
                    </td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td>
                        <input type="button" value="确定" class="btn btn-primary" @click="ok"></input>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from "axios";
import moment from "moment";
import {ref,reactive,onMounted} from "vue"
import {useRoute,useRouter} from "vue-router"
import {useStore} from "@/stores/user"

const route = useRoute();
const router = useRouter();
const abc = useStore();

let info:any = reactive({
  HouseNum: '',
  KeId: '',
  Num: '',
  State: 0,
  LastNum: '',
  StateYe: 1,
})



const ok=()=>{
    if(info.HouseNum==""){
        alert('病房名称不能为空');
        return
    }
    if(info.HouseNum.length>6){
        alert('病房名称不能超过6个字符');
        return
    }
    if(info.KeId==""){
        alert('请选择科室');
        return
    }
    if(info.Num==""){
        alert('请输入房间数量');
        return
    }
    if(info.LastNum==""){
        alert('请输入剩余房间数量');
        return
    }
    axios({
        url:'/api/YeHotels/AddHouse',
        method:'post',
        data:info
    })
    .then(res=>{
        console.log(res);
        if(res.data==-1){
            alert('已有该房号 请重新添加');
            return;
        }
        if(res.data>0){
            alert('添加成功');
            router.push("/houseShow")
            return;
        }
        alert('添加失败');
        return;
    })
    .catch(err=>{
        console.log(err);
        
    })
}

let list:any = ref([])

onMounted(()=>{
        getkeroom();
})
const getkeroom=()=>{
    axios({
        url:'/api/YeHotels/GetKeRooms',
        method:'get',
    })
    .then(res=>{
        console.log(res);
        list.value = res.data
    })
    .catch(err=>{
        console.log(err);
        
    })
}
</script>

<style scoped>

</style>